﻿using System;
using System.Xml.Linq;

namespace XSerialization
{
    /// <summary>
    /// Serializes and deserializes objects into and from XML.
    /// </summary>
    public interface IXSerializer
    {
        /// <summary>
        /// Deserializes the XML contained by the specified file.
        /// </summary>
        /// <param name="document">The File that contains the XML to deserialize.</param>
        /// <param name="type">The Type of the object that this XSerializer can deserialize.</param>
        /// <returns>The Object being deserialized.</returns>
        object Deserialize(string document, Type type);

        /// <summary>
        /// Deserializes the XML contained by the specified XDocument.
        /// </summary>
        /// <param name="document">The XDocument that contains the XML to deserialize.</param>
        /// <param name="type">The Type of the object that this XSerializer can deserialize.</param>
        /// <returns>The Object being deserialized.</returns>
        object Deserialize(XDocument document, Type type);

        /// <summary>
        /// Deserializes the XML contained by the specified XDocument.
        /// </summary>
        /// <param name="document">The XDocument that contains the XML to deserialize.</param>
        /// <param name="o">The instance of the object that this XSerializer can deserialize. Only for the root Object and overrides all xml binding properties.</param>
        /// <returns>The Object being deserialized.</returns>
        object Deserialize(XDocument document, object o);

        /// <summary>
        /// Deserializes the XML contained by the specified XElement.
        /// </summary>
        /// <param name="element">The XElement that contains the XML to deserialize.</param>
        /// <param name="type">The Type of the object that this XSerializer can deserialize.</param>
        /// <param name="o">The instance of the object that this XSerializer can deserialize, optional</param>
        /// <returns>The Object being deserialized.</returns>
        object DeserializeElement(XElement element, Type type, object o = null);

        /// <summary>
        /// Serializes the specified Object and writes the XML to a file.
        /// </summary>
        /// <param name="o">The object to serialize.</param>
        /// <param name="rootName">XML root node name.</param>
        /// <param name="fileName">The file used to write the XML.</param>
        void Serialize(object o, string rootName, string fileName);

        /// <summary>
        /// Serializes the specified Object and writes the XML to a XDocument.
        /// </summary>
        /// <param name="o">The object to serialize.</param>
        /// <param name="rootName">XML root node name.</param>
        XDocument Serialize(object o, string rootName);

        /// <summary>
        /// Serializes the specified Object and writes the XML to a XElement.
        /// </summary>
        /// <param name="o">The object to serialize.</param>
        /// <param name="rootName">XML root node name.</param>
        XElement SerializeElement(object o, string rootName);
    }
}
